package com.ava.avamedia.lottery;

import java.util.ArrayList;

import com.ava.avamedia.MainActivity;
import com.ava.avamedia.R;
import com.ava.avamedia.adapter.MenuAdapter;
import com.ava.avamedia.lottery.mienbac.MBResultsActivity;
import com.ava.avamedia.lottery.miennam.MNResultsActivity;
import com.ava.avamedia.lottery.mientrung.MTResultsActivity;
import com.ava.avamedia.util.Constants;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MenuActivity extends Activity {
	private int region;
	private String url = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_region);
		region = getIntent().getIntExtra(Constants.REGION, 0);
		if (region != 0) {
			url = getIntent().getStringExtra(Constants.URL_RESULT);
		}
		ListView listView = (ListView) findViewById(R.id.activity_region_list_view);
		MenuAdapter adapter = new MenuAdapter(this);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				changeActivity(arg2);
			}

		});

	}

	public void changeActivity(int index) {
		switch (region) {
		case 0:
			MBacAction(index);
			break;
		case 1:
			MTAction(index);
			break;
		case 2:
			MNAction(index);
			break;
		default:
			break;
		}
	}

	public void MTAction(int index) {
		switch (index) {
		case 0:

			break;
		case 1:
			Intent intent = new Intent();
			intent.setClass(MenuActivity.this, MTResultsActivity.class);
			intent.putExtra(Constants.URL_RESULT, url);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_SINGLE_TOP);
			startActivity(intent);
			break;
		case 2:

			break;
		case 3:

			break;

		default:
			break;
		}
	}

	public void MNAction(int index) {
		switch (index) {
		case 0:

			break;
		case 1:
			Intent intent = new Intent();
			intent.setClass(MenuActivity.this, MNResultsActivity.class);
			intent.putExtra(Constants.URL_RESULT, url);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_SINGLE_TOP);
			startActivity(intent);
			break;
		case 2:

			break;
		case 3:

			break;

		default:
			break;
		}
	}

	public void MBacAction(int index) {
		switch (index) {
		case 0:

			break;
		case 1:
			Intent intent = new Intent();
			intent.setClass(MenuActivity.this, MBResultsActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_SINGLE_TOP);
			startActivity(intent);
			break;
		case 2:

			break;
		case 3:

			break;

		default:
			break;
		}
	}

}
